added SSCLI 1.0
[windows-sources.git] / shared source / wpf / src / host / dll / urlmoninterop.cxx
blobfe77ffc9bd9accab4ecf904869ff7959b6ffba48
1 //+-----------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Description: This file is a common point of interop with the
6 // security Manager. It also stores an instance of
7 // security Manager such that we do not need to keep
8 // CoCreating it over and over.
9 //
10 // History:
11 // 2005/06/14 - Created the file
12 // 2007/09/20 - [....]
13 // Ported Windows->DevDiv. See SourcesHistory.txt.
15 //------------------------------------------------------------------------
17 #include "Precompiled.hxx"
18 #include "urlmoninterop.hxx"
19 #include "SecurityManagerSiteImpl.hxx"
21 #ifndef MAXDWORD
22 // From winnt.h
23 #define MAXDWORD 0xffffffff
24 #endif
27 //initialize static variable
28 IInternetSecurityManager *UrlmonInterop::s_pInternetSecurityManager = NULL;
29 IInternetSecurityMgrSite *UrlmonInterop::s_pSecurityMgrSiteImpl = NULL;
33 //call this only when you are done using the securitymanager
34 HRESULT UrlmonInterop::ReleaseSecurityManager()
36 ReleaseInterface(UrlmonInterop::s_pInternetSecurityManager);
37 ReleaseInterface(UrlmonInterop::s_pSecurityMgrSiteImpl);
38 return S_OK;
41 // convenience functionality if you want to get an instance of this pointer
42 // the expectation is that the consumer of this interface calls release on the interface
43 // after he/she is done
44 HRESULT UrlmonInterop::GetSecurityManager(__out_ecount_opt(1)IInternetSecurityManager **ppInternetSecurityManager)
46 HRESULT hr = S_OK;
47 // check for null pointer and send it back
48 if(ppInternetSecurityManager == NULL)
50 CKHR(E_INVALIDARG);
52 if(s_pInternetSecurityManager == NULL)
54 // cocreate the pointer to the COM interface we require
55 // CLSID for internet security managed "7b8a2d94-0ac9-11d1-896c-00c04Fb6bfc4"
56 // GUID for the interface we want to extract "79eac9ee-baf9-11ce-8c82-00aa004ba90b"
57 CKHR(CoCreateInstance(CLSID_InternetSecurityManager,
58 NULL, CLSCTX_INPROC_SERVER,
59 IID_IInternetSecurityManager,
60 (void **)&s_pInternetSecurityManager));
62 *ppInternetSecurityManager = s_pInternetSecurityManager;
63 s_pInternetSecurityManager->AddRef();
64 Cleanup:
65 return hr;
68 // This code takes the url action to invoke and calls it after it
69 // creates an instance of the InternetSecurityManager
70 HRESULT UrlmonInterop::ProcessUrlActionWrapper(
71 DWORD dwurlAction,
72 __in_ecount(1) LPOLESTR pUrl,
73 __in_ecount_opt(1)COleDocument* pOleDoc,
74 __out_ecount(1)BOOL &fAllow)
76 HRESULT hr = S_OK;
77 DWORD dwPolicy = URLPOLICY_DISALLOW;
78 IInternetSecurityManager *pSecurityManager = NULL;
79 Assert(pUrl != NULL);
80 CKHR(GetSecurityManager(&pSecurityManager));
82 UrlmonInterop::s_pSecurityMgrSiteImpl = (IInternetSecurityMgrSite*)new SecurityManagerSiteImpl(pOleDoc);
83 // create an object and register it
84 CKHR(RegisterSecurityManagerSite());
86 // ProcessUrlAction will do the right thing based on call and registry settings
87 CKHR(pSecurityManager->ProcessUrlAction(pUrl,
88 dwurlAction,
89 (BYTE *) &dwPolicy,
90 sizeof(dwPolicy),
91 NULL,
93 PUAF_DEFAULT,
94 NULL));
95 //false if user clicked no true otherwise
96 fAllow = (dwPolicy == URLPOLICY_ALLOW);
97 Cleanup:
98 ReleaseInterface(pSecurityManager);
100 return hr;
103 HRESULT UrlmonInterop::RegisterSecurityManagerSite()
105 HRESULT hr = S_OK;
106 CKHR(UrlmonInterop::s_pInternetSecurityManager->SetSecuritySite((IInternetSecurityMgrSite*)UrlmonInterop::s_pSecurityMgrSiteImpl));
107 Cleanup:
108 return hr;